//
//  headerView.m
//  WULIHH
//
//  Created by Gamefire on 16/4/27.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "headerView.h"
#import "Header.h"
#import "UserInfoModel.h"


#import "UIImageView+WebCache.h"

@interface headerView ()
{
    UILabel *labelname;
    UIImageView *headerImageView;
    UILabel *FocusOnNum;
    UILabel *fansNum;
    
    UIButton *button;
    UIButton *button2;
    UIButton *button3;
    UIImage *_image;
}

@end



@implementation headerView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        [self Topheader];
        [self headerbtn];
    
    
    }
    return self;
}



- (void)Topheader{
    
    [self setUserInteractionEnabled:YES];
    UIView *headview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 142)];
    [headview setBackgroundColor:uicolor(255, 204, 0)];
    [self addSubview:headview];
    
    
    labelname = [[UILabel alloc] initWithFrame:CGRectMake(WithView / 2.0 - 115.0 / 2.0, 27.5, 115, 25)];
//    [labelname setBackgroundColor:[UIColor redColor]];
    [labelname setTextAlignment:NSTextAlignmentCenter];
    [headview addSubview:labelname];
    
    headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2.0 - 123.0 / 4.0, 63 , 123.0 / 2.0, 123.0 / 2.0)];
//    [headerImageView setBackgroundColor:[UIColor redColor]];
    [headerImageView setUserInteractionEnabled:YES];
    [headview addSubview:headerImageView];
    UITapGestureRecognizer *tags = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TouchEvent)];
    [headerImageView addGestureRecognizer:tags];
    
    _image = [UIImage imageNamed:@"shezhi1.png"];
    UIImageView *rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 28, 30, _image.size.width, _image.size.height)];
    [rightImageView setUserInteractionEnabled:YES];
//    [rightImageView setBackgroundColor:[UIColor greenColor]];
    [headview addSubview:rightImageView];
    
//    UITapGestureRecognizer *settag = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SetEvent)];
//    [rightImageView addGestureRecognizer:settag];
    
    UIButton *setUpButton = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 60, 27.5,60, 60)];
//    [setUpButton setBackgroundColor:[UIColor redColor]];
    [setUpButton addTarget:self action:@selector(SetEvent) forControlEvents:UIControlEventTouchUpInside];
    [headview addSubview:setUpButton];
    
    
    UILabel *FocusOnLabel = [[UILabel alloc] initWithFrame:CGRectMake(50.0, 75, 40.5, 12.5)];
//    [FocusOnLabel setBackgroundColor:[UIColor redColor]];
    [headview addSubview:FocusOnLabel];
    
    FocusOnNum = [[UILabel alloc] initWithFrame:CGRectMake(44.0,95.0, 50.0, 15.0)];
//    [FocusOnNum setBackgroundColor:[UIColor redColor]];
    [headview addSubview:FocusOnNum];
    
    UILabel *fansLabel = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width  - 91.5, 75, 40.5, 12.5)];
    [headview addSubview:fansLabel];
    
    fansNum = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 94.0 , 95.0, 50.0, 15.0)];
//    [fansNum setBackgroundColor:[UIColor redColor]];
    [headview addSubview:fansNum];
    
    [labelname setTextAlignment:NSTextAlignmentCenter];
    labelname.font = [UIFont boldSystemFontOfSize:20];
    //    [_labelname setText:_titleNameString];
    
    headerImageView.layer.cornerRadius = 123.0 /4.0;
    
    headerImageView.layer.borderWidth = 1.5f;
    [headerImageView.layer setMasksToBounds:YES];
    headerImageView.layer.borderColor =[UIColor whiteColor].CGColor;
    [headerImageView setContentMode:UIViewContentModeScaleAspectFill];
    [headerImageView.layer setOpaque:NO];
    
    //    [self setBackgroundColor:UIColorRGBA(255.0, 204.0, 0, 1)];
    
//    UIImage *image = [UIImage imageNamed:@"shezhi1.png"];
    [rightImageView setImage:_image];
    
    [FocusOnLabel setText:@"已关注"];
    [FocusOnLabel setTextAlignment:NSTextAlignmentCenter];
    FocusOnLabel.font = [UIFont systemFontOfSize:11];
    
    
    FocusOnNum.font = [UIFont systemFontOfSize:14];
    [FocusOnNum setTextAlignment:NSTextAlignmentCenter];
    //    [_FocusOnNum setText:_fansString];
    
    [fansLabel setText:@"粉丝"];
//    [fansLabel setBackgroundColor:[UIColor redColor]];
    [fansLabel setTextAlignment:NSTextAlignmentCenter];
    fansLabel.font = [UIFont systemFontOfSize:11];
    
    [fansNum setTextAlignment:NSTextAlignmentCenter];
    fansNum.font = [UIFont systemFontOfSize:14];
}

- (void)headerbtn{
//    for (int i = 0; i < 3; i++) {
        button = [[UIButton alloc] initWithFrame:CGRectMake(0, 142, WithView/3.0, 42)];
//        NSArray *textArr = @[@"收藏",@"作品",@"消息"];
        [button setTitle:@"收藏" forState:UIControlStateNormal];
        [button setBackgroundColor:[UIColor whiteColor]];
        [button.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTag:1];
        [button addTarget:self action:@selector(headerTouchEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
//    }
    
    button2 = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(button.frame), 142, WithView/3.0, 42)];
    //        NSArray *textArr = @[@"收藏",@"作品",@"消息"];
    [button2 setTitle:@"作品" forState:UIControlStateNormal];
    [button2 setBackgroundColor:uicolor(255, 247, 217)];
    [button2.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button2 setTag:2];
    [button2 addTarget:self action:@selector(headerTouchEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button2];

    button3 = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(button2.frame), 142, WithView/3.0, 42)];
    //        NSArray *textArr = @[@"收藏",@"作品",@"消息"];
    [button3 setTitle:@"消息" forState:UIControlStateNormal];
    [button3 setBackgroundColor:uicolor(255, 247, 217)];
    [button3.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button3 setTag:3];
    [button3 addTarget:self action:@selector(headerTouchEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button3];

}






- (void)loadUserInfo
{
    [labelname setText:[UserInfoModel nameString]];
    [headerImageView setImage:[UIImage imageWithData:[UserInfoModel imageHeadData]]];
    [FocusOnNum setText:[UserInfoModel starString]];
    [fansNum setText:[UserInfoModel fllowString]];
}




- (void)TouchEvent{
   
    if (_MheaderViewDelegate && [_MheaderViewDelegate respondsToSelector:@selector(pushCenter)])
    {
        [_MheaderViewDelegate pushCenter];
    }
}



- (void)SetEvent{
    
//    NSLog(@"nihao");
    if (_MheaderViewDelegate && [_MheaderViewDelegate respondsToSelector:@selector(pushSetting)])
    {
        [_MheaderViewDelegate pushSetting];
    }
}


- (void)headerTouchEvent:(UIButton *)btn
{
    if (btn.tag == 1) {
        [button setBackgroundColor:[UIColor whiteColor]];
        [button2 setBackgroundColor:uicolor(255, 247, 217)];
        [button3 setBackgroundColor:uicolor(255, 247, 217)];
    }else if (btn.tag == 2){
        [button setBackgroundColor:uicolor(255, 247, 217)];
        [button2 setBackgroundColor:[UIColor whiteColor]];
        [button3 setBackgroundColor:uicolor(255, 247, 217)];
    }else if (btn.tag == 3){
        [button setBackgroundColor:uicolor(255, 247, 217)];
        [button2 setBackgroundColor:uicolor(255, 247, 217)];
        [button3 setBackgroundColor:[UIColor whiteColor]];
    }
    if (_MheaderViewDelegate && [_MheaderViewDelegate respondsToSelector:@selector(buttonWithTag:)]) {
        [_MheaderViewDelegate buttonWithTag:btn.tag];
    }
}
@end
